<template>
  <div class="exam">
<!--    搜索栏-->
    <el-form :inline="true" :model="key" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="key" placeholder="请输入公司名称或职位" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
<!--    表格-->
    <el-table
      :data="tableData"
      style="width: 100%"
      border>

      <el-table-column
        label="单位名称">
        <template v-slot="scope">
          <span style="margin-left: 10px">{{ scope.row.Name }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="单位地址">
        <template v-slot="scope">
          <span style="margin-left: 10px">{{ scope.row.Address }}</span>
        </template>
      </el-table-column>

      <el-table-column
        prop="ContactInfo"
        label="单位联系方式">
        <template v-slot="scope">
          <span style="margin-left: 10px">{{ scope.row.ContactInfo }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="职位名称">
        <template v-slot="scope">
          <span style="margin-left: 10px">{{ scope.row.PositionName }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="薪水">
        <template v-slot="scope">
          <span style="margin-left: 10px">{{ scope.row.Salary }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="岗位要求">
        <template v-slot="scope">
          <span style="margin-left: 10px">{{ scope.row.Responsibilities }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="申请面试">
        <template v-slot="scope">
          <el-button type="primary" @click="apply(scope.$index)">申请</el-button>
        </template>

      </el-table-column>

    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pagination.current"
      :page-sizes="[5, 10]"
      :page-size="pagination.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pagination.total"
      class="page"
    ></el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [], //获取后端招聘信息
      pagination: { //分页
        current: 1, //当前页
        total: null, //记录条数
        size: 5 //每页条数
      },
      key:null
    }
  },
  created() {
    this.getInterviewInfo()
  },
  methods: {
    getInterviewInfo() { //分页查询所有招聘信息
      this.$axios({
        url:'/api/interview/interviewList',
        method:'get',
        params:{
          page:this.pagination.current,
          size:this.pagination.size,
        },
        headers:{
          "Authorization":this.$cookies.get("token")
        }
      }).then(res =>{
        this.pagination=res.data.data
        this.tableData = res.data.data.records
        console.log(this.tableData)
      })
    },
    //改变当前记录条数
    handleSizeChange(val) {
      this.pagination.size = val
      if(this.key==null)
        this.getInterviewInfo()
      else
        this.onSubmit()
    },
    //改变当前页码，重新发送请求
    handleCurrentChange(val) {
      this.pagination.current = val
      if(this.key==null)
        this.getInterviewInfo()
      else
        this.onSubmit()
    },
    //查询
    onSubmit(){
      this.$axios({
        url:'/api/interview/search',
        method:'get',
        params:{
          page:this.pagination.current,
          size:this.pagination.size,
          key:this.key,

        },
        headers:{
          "Authorization":this.$cookies.get("token")
        }
      }).then(res =>{
        this.pagination=res.data.data
        this.tableData = res.data.data.records
        // console.log("complete")
      })
    },
    //申请面试
    apply(index){
      this.$axios({
        url:'/api/user/apply',
        method:'post',
        data:this.tableData[index],
        headers:{
          'Authorization':this.$cookies.get('token')
        }
        }).then(res =>{
        if(res.data.code === 0){
          this.$message.success("申请成功")
        }else{
          this.$message.error("申请失败")
        }
      })
    }
  },
};
</script>
<style lang="less" scoped>
.exam {
  padding: 0px 40px;
  .page {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .edit{
    margin-left: 20px;
  }
}
</style>
